﻿<%@ page language="C#" masterpagefile="MasterPageFrame.master" autoeventwireup="true" inherits="admin_cardtypelist, App_Web_bgx0xzll" title="卡管理 -> 卡产品设定" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.btnViewPic{padding-right:30px;text-decoration:none;}
.btnViewPic:hover{color:red}
.viewpic{position:relative;display:none}
.viewpic span{cursor:pointer;background-image:url('css/error.gif');width:16px;height:16px;display:block;position:absolute;top:5px;right:0px;background-repeat:no-repeat;background-position:center center}
.cardimage{width:80px;height:50px}
#linktoproduct li{position:relative;padding-top:5px;padding-bottom:5px}
#linktoproduct li span{position:absolute;right:0px;top:5px}
a.d1{text-decoration:none;font-weight:bold;padding-left:6px;padding-right:6px;font-family:宋体}
a.d1:hover{color:#ff0000;}
</style>
<script type="text/javascript">
function __add()
{
	$form.reset("form0");

	__showdialog("添加卡分类");
}

function __delete(_cardtypeid)
{
	if (confirm("您真的要删除此卡分类吗？"))
	    location = "cardtypedelete.aspx?cardtypeid=" + _cardtypeid;
}

function __modify(_cardtypeid) {
    //window.open("xmlcardtype.aspx?cardtypeid=" + _cardtypeid);
    $form.ElementsDataFromXML("form0", "xmlcardtype.aspx?cardtypeid=" + _cardtypeid);
	__showdialog("修改卡分类");
}
function __formcheck(event)
{
	if (!jsformcheck(event))
	    return false;
	var r="";
	$("#linktoproduct li").each(function() {
	    if (r == "") {
	        r = $(this).attr("productid");
	    }
	    else {
	        r += ","+ $(this).attr("productid");

	    }
	});

	$("#productids").val(r);
	$("#cardimage").val($("#PicPath1").val());
	
	return true;
}

function __showdialog(_t)
{

	$('#dialog').dialog({
		autoOpen: false,
		width: 680,
		resizable: false,
		modal: true,
		title:_t
	});
	$("#PicPath1").val($("#cardimage").val());
	__renderViewPic();
	$('#dialog').dialog('open');

	//window.open("xmlproduct.aspx?json=json&productid=" + $("#productids").val());
	__reanderlinkproduct();
}

//上传===========================

function __showuploaddialog(_t) {

    $('#dialogupload').dialog({
        autoOpen: false,
        width: 560,
        resizable: false,
        title: _t,
        modal: true
    });

    $('#dialogupload').dialog('open');
    

}

function uploadSuccess__callback(file, serverData) {
    eval(serverData);
    if (returnValue.errdescription != "") {
        alert(serverData);
        return;
    }

    if (returnValue.fileurl != "") {
        __showFileUploaded(file, returnValue.fileurl);
    }
}

function __showFileUploaded(file, __filePath) {

    $("#PicPath" + boundUploadElement).val(__filePath);
    $('#dialogupload').dialog('close');
    __renderViewPic();
}

function __upload(s) {
    boundUploadElement = s;
    gE("iframeupload").contentWindow.document.location.replace("uploadfile.aspx");
    __showuploaddialog("图片上传");
}

function __removepic(s) {
    $("#PicPath" + s).val("");
    __renderViewPic();
}

function __renderViewPic() {
    var i;

    for (i = 1; i <= 1; i++) {
        if ($("#PicPath" + i).val() != "") {
            $("#APicPath" + i).attr("target", "_blank");
            $("#APicPath" + i).attr("href", $("#PicPath" + i).val());
            var _t = $("#PicPath" + i).val().split("/");
            $("#APicPath" + i).html("查看已上传文件 >> " + _t[_t.length - 1]);
            $("#viewpic" + i).show();
        }
        else {
            $("#APicPath" + i).html("");
            $("#viewpic" + i).hide();
        }
    }
}
function __move(d,s) {
    var elem = document.getElementById("p" + s);
    if (d == "up")
    {

        if (elem.previousSibling) {
            //alert(elem.parentElement.parentElement.innerHTML);
            elem.swapNode(elem.previousSibling);
        }
    }
    if (d == "down")
    {
        if (elem.nextSibling) {
            elem.swapNode(elem.nextSibling);
        }
    }
}

//*******************
//挂接商品
function __reanderlinkproduct() {

    if ($("#productids").val()) {
        var kk = "";
        //alert($("#productids").val());
        $ajax.load({ url: "xmlproduct.aspx", data: "json=json&productid=" + $("#productids").val(), type: "json", method: "GET" });
        //alert($ajax.responseText);
        var i, _html = "<ol>";
        for (i = 0; i < $ajax.responseJson.length; i++) {
            if (kk != "") {
                kk = kk + "," + $ajax.responseJson[i].productid;
            }
            else {
                kk = $ajax.responseJson[i].productid;
            }
            _html += "<li id=\"p" + $ajax.responseJson[i].productid + "\" productid=\"" + $ajax.responseJson[i].productid + "\"><a href=\"" + $ajax.responseJson[i].showpageurl + "?productid=" + $ajax.responseJson[i].productid + "\" target=\"_blank\">" + unescape($ajax.responseJson[i].productname) + "</a><span><a href=\"javascript:__removeproduct(" + $ajax.responseJson[i].productid + ")\" class=\"d\">移除</a>|<a href=\"javascript:__move('up','" + $ajax.responseJson[i].productid + "');\" class=\"d1\">↑</a>|<a href=\"javascript:__move('down','" + $ajax.responseJson[i].productid + "');\" class=\"d1\">↓</a></span></li>"
        }
        _html += "</ol>";
        $("#productids").val(kk);
        $("#linktoproduct").html(_html);
        $("#linktoproduct li").hover(function() {
            $(this).addClass("mouseover");
            },
            function() {
            $(this).removeClass("mouseover");
            }
        );
    }
}

function __addlinkproduct() {

    $('#dialogproductselect').dialog({
        autoOpen: false,
        width: 1000,
        resizable: false,
        title: "选择挂接商品",
        modal: true
    });
    document.getElementById("iframeproductselect").contentWindow.document.location = "productselect.aspx";
    $('#dialogproductselect').dialog('open');
}

function __addtoproductids() {

    var v = document.getElementById("iframeproductselect").contentWindow.$form.getCheckboxValue("productid");
    if (!v) {
        alert("请选择您要挂接到商品");
        return;
    }

    var _t = $("#productids").val().split(",");
    var v2 = v.split(",");
    var i, j;
    var hasIt;
    var r = $("#productids").val();
    for (j = 0; j < v2.length; j++) {
        hasIt = false;
        for (i = 0; i < _t.length; i++) {
            if (_t[i] == v2[j]) {
                hasIt = true;
                break;
            }
        }
        if (!hasIt) {
            if (r == "") {
                r = v2[j];
            }
            else{
                r+="," + v2[j];
            }
        }
    }
    //alert(r);
    alert("挂接成功");

    $("#productids").val(r);
    __reanderlinkproduct();
}

function onpagechange() {
    document.getElementById("iframeproductselect").contentWindow.$form.focusCheckbox("productid", $("#productids").val());
}

function __removeproduct(_id) {
    $("#p" + _id).remove();
    var _t = $("#productids").val().split(",");
    var i;
    var r;
    for (i = 0; i < _t.length; i++) {
        if (_t[i] != _id) {
            if (r) {
                r += "," + _t[i];
            }
            else {
                r = _t[i];
            }
        }
    }
    $("#productids").val(r);
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="caption">
        <a class="btn" id="btnAdd" onclick="javascript:__add();">添加卡产品设定</a>
    </div>
    <div id="notetypelist" runat="server">

    </div>
    <div id="dialog" title="" class="X-dialog">
	    <form name="form0" id="form0" action="cardtypeupdate.aspx" method="post" onsubmit="javascript:return __formcheck(event);">
  	    <table border="0" cellspacing="0" cellpadding="0" width="100%">
	        <tr>
	          <td class="WebNote_Field">礼品卡名称</td>
	          <td><input type="text" name="cardtypename" id="cardtypename" maxlength="50" datatype="string" nullabled="false" alerttext="卡分类名称" autocomplete="off"  /></td>
	        </tr>
	        <tr>
	          <td class="WebNote_Field">卡价值</td>
	          <td><input type="text" name="cardprice" id="cardprice" maxlength="50" datatype="number" nullabled="false" alerttext="卡分类名称" autocomplete="off"  />元</td>
	        </tr>
	        
	        <tr>
	          <td class="WebNote_Field">卡图</td>
	          <td>
	                <input type="button" value="上传" onclick="javascript:__upload('1');"/>
	                <span class="viewpic" id="viewpic1"><a id="APicPath1" class="btnViewPic"></a><span onclick="javascript:__removepic(1)"></span></span>
                    <input type="hidden" id="PicPath1" name="PicPath1" />
	                <div class="divHelp">只能上传<%=core.setting.get("uploadallowmaxfilesize").ToString()%>K以下大小的图片。图片尺寸为：宽428像素，高270像素。</div>
	          </td>
	        </tr>
	        <tr>
	          <td class="WebNote_Field">排序号</td>
	          <td>
	            <input type="text" name="sortNum" id="sortNum" maxlength="255" datatype="number" nullabled="false" alerttext="排序号" autocomplete="off" />
	            <div class="divHelp">排序号小于等于5的礼品卡，将会显示在flash动画中。</div>
	          </td>
	        </tr>
	        <tr>
	          <td colspan="2">
	            <fieldset><legend>挂接商品</legend>
	                <input type="button" value="添加挂接商品" onclick="javascript:__addlinkproduct();"/>
	                <div id="linktoproduct"></div>
	            </fieldset>
	          </td>
	        </tr>
    	    <tr>
	          <td></td>
	          <td>
	            <input type="hidden" name="cardimage" id="cardimage" maxlength="255" datatype="string" nullabled="true" alerttext="卡图" autocomplete="off" />
	            <input type="hidden" name="productids" id="productids" maxlength="255" datatype="string" nullabled="true" alerttext="挂接到产品编号" autocomplete="off" />
			    <input type="hidden" name="cardtypeid" id="cardtypeid" />
			    <input type="submit" value="提交" />
	          </td>
	        </tr>
	    </table>
	    </form>
    </div>
    
    <div id="dialogupload" class="X-dialog">
        <iframe src="" id="iframeupload" frameborder="0" style="width:100%;height:260px"></iframe>
	</div>
	
	<div id="dialogproductselect" class="X-dialog">
	    <iframe src="" id="iframeproductselect" frameborder="0" style="width:100%;height:500px"></iframe>
	    <p style="text-align:center"><input type="button" value="把选中的产品挂接到此卡" onclick="__addtoproductids();"/></p>
	</div>
</asp:Content>

